using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace shfa.snomtastic.data
{
    public partial class SqlDataProvider
    {

        public Guid InsertGroup(Guid configurationId, string name)
		{
            return new Guid(Convert.ToString(SqlHelper.ExecuteScalar(ConnectionString, "sp_GroupInsert", GetNull(configurationId), name)));
		}

        public int UpdateGroup(Guid groupId, Guid configurationId, string name)
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_GroupUpdate", GetNull(groupId), GetNull(configurationId), name));
		}

        public int DeleteGroup(Guid groupId) 
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_GroupDelete", groupId));
		}

        public DataRow SelectGroup(Guid groupId) 
        {    
			DataSet ds = SqlHelper.ExecuteDataset(ConnectionString, "sp_GroupSelect", groupId);
            if (ds.Tables.Count > 0)
                if (ds.Tables[0].Rows.Count > 0)
                    return ds.Tables[0].Rows[0];

            return null;
		}

		public DataTable SelectGroups() 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_GroupSelectAll").Tables[0];
        }

		public DataTable SelectGroupsByConfiguration(Guid configurationId) 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_GroupSelectByConfiguration", configurationId).Tables[0];
        }

    }

}
